package com.mybatis.controller;

import com.mybatis.entity.ItemsCustom;
import com.mybatis.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by 85243 on 2017/5/19.
 */
@Controller
public class ItemsController {
    @Autowired
    private ItemsService itemsService;

    //商品查询
    @RequestMapping("/queryItems") //实际网址后面跟了.action
    public ModelAndView queryItems(HttpServletRequest request) throws Exception {
        List<ItemsCustom> itemsList = itemsService.findItemsList(null);

        //返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();

        //相当于request的setAttribute，在jsp页面中通过itemsList取数据
        modelAndView.addObject("itemsList",itemsList);

        return modelAndView;
    }
}
